package com.freshcity.page.common
{
	import com.freshcity.common.IsLimited;
	import com.freshcity.component.container.Component;
	import com.freshcity.component.container.HBox;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.graphics.MessageStatus;
	import com.freshcity.lib.tooltip.ToolTipsManager;
	import com.freshcity.utils.StringUtil;
	import com.maccherone.json.JSON;
	
	import fl.containers.ScrollPane;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	public class FriendDetail extends Component
	{
		public var home:UserHome;
		private var user:*;
		private var cond:*;
		private var txtFormat:TextFormat;
		private var ypos:int=0;
		private var mainPanel:ScrollPane;
		private var mainSp:Sprite;
		
		public function FriendDetail(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			txtFormat = new TextFormat("宋体", 12);
			txtFormat.leading = 6;
			this.setSize(500,300);
			this.mouseEnabled=false;
			super(parent, xpos, ypos);
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			mainPanel = new ScrollPane();
			mainPanel.width = 480;
			mainPanel.height = 300;
			this.addChild(mainPanel);
		}
		
		//自我描述
		private function createUserDesc():void
		{
			createTitleLabel("交友独白：");
			ypos += 25;
			
			var contentTf:TextField=new TextField();
			contentTf.defaultTextFormat = txtFormat;
			contentTf.autoSize=TextFormatAlign.LEFT;
			contentTf.text = this.user.selfDesc;
			contentTf.width=320;
			contentTf.wordWrap=true;
			contentTf.x = 65;
			contentTf.y = ypos;
			mainSp.addChild(contentTf);
			
			ypos += 80;
		}
		
		private function createFriendCond():void
		{
			if(this.user.qqNo == '' || this.cond.ageFrom == undefined) return;
			
			createTitleLabel("择友要求：");
			ypos += 25;
			createProperty('年龄', this.cond.ageFrom+" - "+this.cond.ageTo,75,ypos);
			
			var s1:String = "不限";
			if(this.cond.addCity!=''){
				s1 = this.cond.addProv + this.cond.addCity;
			}else if(this.cond.addProv!=''){
				s1 = this.cond.addProv;
			}
			
			createProperty('居住地', s1,280,ypos);
			ypos += 25;
			createProperty('身高', this.cond.tallFrom+" - "+this.cond.tallTo,75,ypos);
			
			var s2:String = '不限';
			if(this.cond.degree != ''){
				s2 = this.cond.degree+"及以上";
			}
			createProperty('学历', s2 ,280,ypos);
			ypos += 25;
		}
		
		private function createTitleLabel(label:String):void
		{
			var labelTf:TextField=new TextField();
			labelTf.defaultTextFormat = new TextFormat("黑体", 14);
			labelTf.autoSize=TextFormatAlign.LEFT;
			labelTf.text = label;
			labelTf.x = 65;
			labelTf.y = ypos;
			mainSp.addChild(labelTf);
		}
		
		private function createProperty(label:String,value:String,xpos:Number=0,ypos:Number=0):void
		{
			var tf:TextField=new TextField();
			tf.defaultTextFormat = txtFormat;
			tf.autoSize=TextFormatAlign.LEFT;
			tf.height=20;
			tf.width=180;
			tf.htmlText = StringUtil.addColor(label + " ", "#666666") + value;
			tf.x = xpos;
			tf.y = ypos;
			mainSp.addChild(tf);
		}
		
		override public function show(event:Event=null):void
		{
			this.user=home.data.user;
			this.cond=(user.cond!='')?JSON.decode(user.cond):{};
			ypos = 15;
			mainSp = new Sprite();
			mainSp.mouseEnabled = false;
			createFriendCond();
			createUserDesc(); 
			this.mainPanel.source = mainSp;
			this.mainPanel.update();
			super.show(event);
		}
	}
}
